package com.shiny.concurrency4java.atomic;

import com.shiny.concurrency4java.annoations.ThreadSafe;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.atomic.AtomicReference;

@ThreadSafe
@Slf4j
public class ReferenceExample {

    private AtomicReference<Integer> reference = new AtomicReference<Integer>(0);

    private void safeCount(){
        reference.compareAndSet(0,1);
        reference.compareAndSet(1,3);
        reference.compareAndSet(2,4);
        reference.compareAndSet(3,5);
        reference.compareAndSet(4,0);
    }

    public static void main(String[] args) throws Exception{
        final ReferenceExample cas = new ReferenceExample();
        cas.safeCount();
        log.info("cas atomicI:{}",cas.reference.get());
        return;
    }


}
